<%@ page import="org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils; com.the8thfold.anton.ant.AntJobUser; com.the8thfold.anton.ant.AntScriptUser; com.the8thfold.anton.users.Roles; com.the8thfold.anton.ant.AntJobStatus; com.the8thfold.anton.ant.AntJobRunResults; com.the8thfold.anton.users.User; com.the8thfold.anton.ant.AntJob; com.the8thfold.anton.ant.AntScript" %>
<html>
<head>
    <title>Home</title>
    <meta name="layout" content="mainNoNav" />

</head>
<body>

<div class="css_center" style="width: 50%;">
    <table style="border: none; width: auto;">
        <tr>
            <td colspan="3">
                <div class="css_center">
                    <span id="a" style="">
                        <sec:ifLoggedIn>
                            Hello
                            <a href="${createLink(controller: 'account', action: ".", id: sec.loggedInUserInfo(field: 'userId',''))}"><sec:loggedInUserInfo field="fullName"/></a>
                            | <a href="${createLink(controller: 'logout')}" id="logoutButton">Logout</a>
                        </sec:ifLoggedIn>
                        <sec:ifNotLoggedIn>
                            <a href="${createLink(controller: 'login')}" id="loginButton">Login</a>
                        </sec:ifNotLoggedIn>
                    </span>
                </div>
            </td>
        </tr>
        <tr>
            <td class="" style="width: 245px; ">
                <sec:ifLoggedIn>
                    <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_ADMIN.toString())}">
                        <g:render template="dashboardWidget" model="[title: 'Scripts', trail: 'Script', link: createLink(controller: 'script', action: 'list'), count: AntScript.count(), roles: Roles.ROLE_SCRIPT_ADMIN.toString()]" />
                    </g:if>
                    <g:else>
                        <g:render template="dashboardWidget" model="[title: 'Scripts', trail: 'Script', link: createLink(controller: 'script', action: 'list'), count: AntScriptUser.countByUser(User.findByUserId(sec.loggedInUserInfo(field: 'userId'))) , roles: Roles.ROLE_SCRIPT_ADMIN.toString()]" />
                    </g:else>
                </sec:ifLoggedIn>
                <sec:ifNotLoggedIn>
                    <g:render template="dashboardWidget" model="[title: 'Scripts', trail: 'Script', link: createLink(controller: 'script', action: 'list'), count: AntScript.count(), roles: Roles.ROLE_SCRIPT_ADMIN.toString()]" />
                </sec:ifNotLoggedIn>
            </td>
            <td class="" style="width: 245px;">
                <sec:ifLoggedIn>
                    <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_ADMIN.toString())}">
                        <g:render template="dashboardWidget" model="[title: 'Jobs', trail: 'Job', link: createLink(controller: 'job', action: 'list'), count: AntJob.count(), roles: Roles.ROLE_JOB_RUN.toString()]" />
                    </g:if>
                    <g:else>
                        <g:render template="dashboardWidget" model="[title: 'Jobs', trail: 'Job', link: createLink(controller: 'job', action: 'list'), count: AntJobUser.countByUser(User.findByUserId(sec.loggedInUserInfo(field: 'userId'))), roles: Roles.ROLE_JOB_RUN.toString()]" />
                    </g:else>
                </sec:ifLoggedIn>
                <sec:ifNotLoggedIn>
                    <g:render template="dashboardWidget" model="[title: 'Jobs', trail: 'Job', link: createLink(controller: 'job', action: 'list'), count: AntJob.count(), roles: Roles.ROLE_JOB_RUN.toString()]" />
                </sec:ifNotLoggedIn>
            </td>
            <td class="" style="width: 245px;">
                <sec:ifLoggedIn>
                    <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_ADMIN.toString())}">
                        <g:render template="dashboardWidget" model="[title: 'Results', trail: 'Run', link: createLink(controller: 'result', action: 'list'), count: AntJobRunResults.count(), roles: Roles.ROLE_RESULTS_VIEW.toString()]" />
                    </g:if>
                    <g:else>
                        <g:render template="dashboardWidget" model="[title: 'Results', trail: 'Run', link: createLink(controller: 'result', action: 'list'), count: AntJobRunResults.countVisibleByUser(sec.loggedInUserInfo(field: 'userId').toString()), roles: Roles.ROLE_RESULTS_VIEW.toString()]" />
                    </g:else>
                </sec:ifLoggedIn>
                <sec:ifNotLoggedIn>
                    <g:render template="dashboardWidget" model="[title: 'Results', trail: 'Run', link: createLink(controller: 'result', action: 'list'), count: AntJobRunResults.count(), roles: Roles.ROLE_RESULTS_VIEW.toString()]" />
                </sec:ifNotLoggedIn>
            </td>
        </tr>
        <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_ADMIN.toString())}">
            <tr>
                <td  class="" style="width: 245px;">
                    <g:render template="dashboardWidget" model="[title: 'Users', trail: 'User', link: createLink(controller: 'account', action: 'list'), count: User.count(), roles: Roles.ROLE_ADMIN.toString()]" />
                </td>

                <td  class="" style="width: 245px;">

                </td>
                <td  class="" style="width: 245px;">
                    <div class="ui-widget-header ui-corner-top css_center" style="padding: 5px 5px; "><h1>
                        Settings
                    </h1></div>
                    <div class="ui-widget-content ui-corner-bottom" style="padding: 15px; text-align: center; height: 125px;">
                        <div class="">
                            <ul style="list-style-type:none;">
                                <li><a href="${createLink(controller: 'settings', action: 'list')}">Configuration</a></li>
                                <li><a href="#">Notifications</a></li>
                            </ul>
                        </div>
                    </div>
                </td>
            </tr>
        </g:if>
    </table>
</div>

</body>
</html>
